﻿using System;
using System.Data;
using System.Net;
using AppEszköz.Config;
using AppEszköz.Log.Service;

namespace AppEszköz.Log
{
    public class ApplicationLogging
    {
        private ApplicationLogging()
        {
        }

        public static string Environment()
        {
            return ConfigHelper.GetConfig("Environment");
        }

        public static DataSet SearchLog(int ApplicationID, DateTime BeginDate, DateTime EndDate, int EventType, string EventDescription, string UserID, string URL, string IPAddress)
        {
            return ApplicationLogging.SearchLog(ApplicationID, BeginDate, EndDate, EventType, EventDescription, UserID, URL, IPAddress, 0);
        }

        public static DataSet SearchLog(int ApplicationID, DateTime BeginDate, DateTime EndDate, int EventType, string EventDescription, string UserID, string URL, string IPAddress, int ResultLimit)
        {
            return new LoggingService()
            {
                Url = ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web",
                    "ApplicationLoggingURL")
            }.SearchLog(ApplicationID, BeginDate, EndDate, EventType, EventDescription, UserID, URL, IPAddress, ResultLimit);
        }

        public static string WriteToLog(int ApplicationID, EventTypes et, string EventDescription, string UserID, string URL, string IPAddress, string[] details)
        {
            return new LoggingService()
            {
                Url = ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web", "ApplicationLoggingURL")
            }.WriteLog(ApplicationID, et, EventDescription, UserID, URL, IPAddress, (object[])details);
        }

        public static DataSet GetApplications()
        {
            return new LoggingService()
            {
                Url = ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web", "ApplicationLoggingURL")
            }.RetrieveApplications();
        }

        public static string LoggingServiceName()
        {
            try
            {
                return ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web", "ApplicationLoggingReportService");
            }
            catch
            {
                return "-";
            }
        }

        public static string LoggingServiceAuditReportPath()
        {
            try
            {
                return ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web", "ApplicationLoggingAuditReportPath");
            }
            catch
            {
                return "-";
            }
        }

        public static NetworkCredential NetworkCredentials()
        {
            return new NetworkCredential(ConfigRegistryHelper.GetConfig("AppTools_" + ApplicationLogging.Environment(), "Web", "ApplicationLoggingReportSerivceNetworkUser"), ConfigRegistryHelper.GetConfig("AppTools", ConfigHelper.GetConfig("Environment"), "ApplicationLoggingReportSerivceNetworkPassword"));
        }
    }
}